package com.example.localbroadcastdemo;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.view.View;

public class OtherActivity extends Activity{
	
	private LocalBroadcastManager lbm;
	private MyReceiver receiver;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_other);
		
		lbm = LocalBroadcastManager.getInstance(this);
		
		IntentFilter filter = new IntentFilter();
		filter.addAction("com.bsss.wenhao");
		
		receiver = new MyReceiver();
		lbm.registerReceiver(receiver, filter);
	}
	
	public void onJumpActivity(View view){
		
		Intent intent = new Intent(OtherActivity.this, MainActivity.class);
		startActivity(intent);
	}
	
	class MyReceiver extends BroadcastReceiver{

		@Override
		public void onReceive(Context context, Intent intent) {
			// TODO Auto-generated method stub
			
			String name = intent.getStringExtra("name");
			Log.d("wenhao","into the onReceive..." + name);
		}
		
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		
		lbm.unregisterReceiver(receiver);
	}
}

